﻿using System;
using System.Security;
using System.Security.Principal;

namespace Sok.Munkae.Core
{
    public class User : Entity, IPrincipal
    {
        private IIdentity identity;
        public User(Organization organization)
        {
            this.Organization = organization;
        }

        public string UserName { get; set; }
        public string Password { get; set; }
        public Organization Organization { get; protected internal set; }
        
        public bool IsInRole(string role)
        {
            throw new NotImplementedException();
        }

        public virtual IIdentity Identity
        {
            get { return identity; }
        }
        
        public virtual User Init()
        {
            if (UserName == null)
            {
                throw new SecurityException("Unable to initialize user Identity. UserName is null.");
            }
            else
            {
                identity = new GenericIdentity(UserName);
            }
            return this;
        }
    }
}